package ca.radiologydb.util;

import java.sql.*;

public class ConnectionManager {
	
	private Connection conn;
	
	public ConnectionManager(String username, String password) {
		
		
		String driverName = "oracle.jdbc.driver.OracleDriver";
		String dbstring = "jdbc:oracle:thin:@gwynne.cs.ualberta.ca:1521:CRS";
		
		try{
		    //load and register the driver
			Class drvClass = Class.forName(driverName); 
			DriverManager.registerDriver((Driver) drvClass.newInstance());
		}
		catch(Exception ex){
		    System.out.println("<hr>" + ex.getMessage() + "<hr>");
		
		}
		
		try{
			//establish the connection 
		    conn = DriverManager.getConnection(dbstring,username,password);
			conn.setAutoCommit(false);
		}
		catch(Exception ex){
		
		    System.out.println("<hr>" + ex.getMessage() + "<hr>");
		}
	}
	
	public ConnectionManager() {
		
		
		String driverName = "oracle.jdbc.driver.OracleDriver";
		String dbstring = "jdbc:oracle:thin:@gwynne.cs.ualberta.ca:1521:CRS";
		
		try{
		    //load and register the driver
			Class drvClass = Class.forName(driverName); 
			DriverManager.registerDriver((Driver) drvClass.newInstance());
		}
		catch(Exception ex){
		    System.out.println("<hr>" + ex.getMessage() + "<hr>");
		
		}
		
		try{
			//establish the connection 
		    conn = DriverManager.getConnection(dbstring,"njliu","s1llyfox");
			conn.setAutoCommit(false);
		}
		catch(Exception ex){
		
		    System.out.println("<hr>" + ex.getMessage() + "<hr>");
		}
	}
	
	public Connection getConnection() {
		return conn;
	}
	
	public void closeConnection() {
		try {
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println("Could not close DB connection.\n");
			e.printStackTrace();
		}
	}

}
